package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.BeanGoodChangjing;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.custom.MyRecyclerView;
import nero.yncc.com.createart.interfaces.InterfaceDoSomeThing;
import nero.yncc.com.createart.utils.MyLayoutManager;

/**
 * Created by nero on 17-6-27.
 */

public class AdapterDetailIn extends RecyclerView.Adapter<AdapterDetailIn.Holder> {

    Context context;
    ArrayList<GodBean.SpecAttr> arrayList;
    HashMap<String, BeanGoodChangjing> hashMap;

    public AdapterDetailIn(Context context, ArrayList<GodBean.SpecAttr> arrayList, HashMap<String, BeanGoodChangjing> hashMap) {
        this.context = context;
        this.arrayList = arrayList;
        this.hashMap=hashMap;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_detail_in, null);
        Holder holer = new Holder(view);
        return holer;
    }

    @Override
    public void onBindViewHolder(Holder holer, int position) {
        final GodBean.SpecAttr bean = arrayList.get(position);
        holer.tv_content.setText(bean.getName());
        MyLayoutManager layout = new MyLayoutManager(context);
        //必须，防止recyclerview高度为wrap时测量item高度0
        layout.setAutoMeasureEnabled(true);
//        view.measure(0,0);
        holer.rc_list.setLayoutManager(layout);

        if(bean.getList()!=null){
            AdapterDetailInandIn adapterDetailInandIn = new AdapterDetailInandIn(context, bean.getList(), new InterfaceDoSomeThing() {
                @Override
                public void doSomething(String id) {
                    bean.setChooseAttrId(id);
                }
            });
            holer.rc_list.setAdapter(adapterDetailInandIn);
            adapterDetailInandIn.notifyDataSetChanged();
        }else{

        }

    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }


    class Holder extends RecyclerView.ViewHolder {
        TextView tv_content;
        MyRecyclerView rc_list;

        public Holder(View itemView) {
            super(itemView);
            tv_content = itemView.findViewById(R.id.tv_content);
//            fl_inside=itemView.findViewById(R.id.fl_inside);
            rc_list = itemView.findViewById(R.id.rc_list);
        }
    }
}
